{% extends 'base.html' %}

{% block content %}
    {# 使用 length 过滤器获取 movies 变量的长度 #}
    <p>豆瓣电影一周口碑榜  Top {{ movies|length }}</p>
   
    <p>{{ movies|length }} Titles</p>
    <form method="post">
        名称 <input type="text" name="title" autocomplete="off" required>
        年份 <input type="text" name="year" autocomplete="off" required>
        <input class="btn" type="submit" name="submit" value="Add">
    </form>
    
    <ul class="movie-list">
        {# 迭代 movies 变量 #}
        {% for movie in movies %}
            {# 等同于 movie['title'] #}
            <li>{{ movie.title }} - {{ movie.year }}
                <span class="float-right">
                    <a class="douban" href="https://search.douban.com/movie/subject_search?search_text={{ movie.title }}"
                        target="Find this movie on DouBan">豆瓣</a>
                    <a class="btn" href="{{ url_for('movie_edit', movie_id=movie.id) }}">编辑</a>
                    <form class="inline-form" method="post" action="{{ url_for('movie_delete', movie_id=movie.id) }}">
                        <input class="btn" type="submit" name="delete" value="删除" onclick="return confirm('Are you sure?')">
                    </form>
                </span>

            </li>
        {# 使用 endfor 标签结束 for 语句 #}
        {% endfor %}
    </ul>

{% endblock %}